< previous page page_583 next page >

Page 583
0583-01.jpg
Figure 26.5
These tables show the difference between using
ascending and descending order in an index.
Table 26.4 Different Seek Comparison Operators and Index Sort Orders Yield Different Results
Seek Comparison OperatorIndex OrderResulting Record
">=", "Smith, A"AscendingSmith, Aaron
"<=", "Smith, Z"AscendingSmith, Francis
">=", "Smith, A"DescendingSchmidt, David
"<=", "Smith, Z"DescendingSmith, Zeke

Notice that you must also be careful when using the > ,< , >=, or <= operator on a descending index. The > (and >=) operator finds the record that occurs later in the index than the specified key value. For that reason, the ">=", "Smith" search on a descending index returns the record Schmidt, David. Similar behavior is exhibited by the < and <= operators. As you can see from the preceding example, you must use care when choosing both the index sort order and the comparison operator with the Seek method to ensure that the desired results are achieved.
As with the Find methods, if a Seek is successful, the record pointer moves. Otherwise, the recordset's NoMatch property is set to True, and the record pointer does not change.
Enabling a Sample Seek
Now you can enhance the sample project to perform a Seek. Because the users shouldn't be expected to type an entire book title to find a match, you can use >= as the seek comparison. This means that even if NoMatch is false, indicating a successful Seek, you need to look at the current record to make sure it meets the users' criteria. Follow these steps:
1. Add a text box named txtSearch to the form.
2. Add a label to identify the text box, and set its Caption property to Search for:.
3. Add a command button named cmdSeek, and set its Caption property to Search.
Figure 26.6 shows the form with the new controls added.

 
< previous page page_583 next page >